const router = require('koa-router')()

const Fredis = require('ioredis')

const fredis=new Fredis()

router.prefix('/fac')

router.post('/', async (ctx, next) => {
    await ctx.render('index', {
        title: 'fac POST成功'
    })
})
router.get('/:xauth', async (ctx, next) => {
    await ctx.render('index', {
        title: ("code is "+ctx.params.xauth)
    })
})

router.post('/:xauth/string', async (ctx, next) => {
    if (ctx.params.xauth=='123'){
       return  ctx.body = 'koa2 post string'

    }
    ctx.body = 'koa2 bad'

})

router.get('/:xauth/string', async (ctx, next) => {
    if (ctx.params.xauth=='123'){
        return  ctx.body = 'koa2 get string'

    }
    else {
        fredis.get()
    }
    ctx.body = 'koa2 bad'

})

router.get('/json', async (ctx, next) => {
    ctx.body = {
        title: 'koa2 json'
    }
})

module.exports = router